#include<iostream>
//#include "opencv2/core/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/opencv.hpp"
#include <fstream>

using namespace std;

int main() {
    const std::string img_path = "imagenet_cat.png";

    // 打印图像大小
    cv::Mat image = cv::imread(img_path);
    std::cout << "图像大小：" << image.size() << std::endl;

    // 调整大小为 224x224
    cv::resize(image, image, cv::Size(224, 224));
    std::cout << "调整后的图像：" << std::endl << image << std::endl;
    

    // 获取图像的通道数
    int channels = image.channels();

    // 将图像数据复制到三维矩阵中
    std::vector<std::vector<std::vector<float>>> threeDMatrix(channels,
                                                              std::vector<std::vector<float>>(image.rows,
                                                                                                std::vector<float>(image.cols)));

    // fourDMatrix
    std::vector<std::vector<std::vector<std::vector<cv::Vec3b>>>> fourDMatrix(1,
       							      std::vector<std::vector<std::vector<cv::Vec3b>>>(3,
            						      std::vector<std::vector<cv::Vec3b>>(image.rows,
                					      std::vector<cv::Vec3b>(image.cols))));

    // 归一化参数
    cv::Mat imagenet_mean = (cv::Mat_<float>(1, 1) << 0.485, 0.456, 0.406);
    cv::Mat imagenet_stddev = (cv::Mat_<float>(1, 1) << 0.229, 0.224, 0.225);

    // 归一化图像数据并输出
    for (int i = 0; i < image.rows; ++i) {
        for (int j = 0; j < image.cols; ++j) {
            for (int c = 0; c < channels; ++c) {
                float normalized_value = (static_cast<float>(image.at<cv::Vec3b>(i, j)[c]) / 255 - imagenet_mean.at<float>(0, c)) / imagenet_stddev.at<float>(0, c);
                threeDMatrix[c][i][j] = normalized_value;
		//fourDMatrix[0][c][i][j] =  normalized_value;
                std::cout << normalized_value << " ";
            }
            std::cout << "| ";
        }
        std::cout << std::endl;
    }
   
    std::cout << "Matrix :" << std::endl;
    std::cout << threeDMatrix.size() << std::endl;
    std::cout << threeDMatrix[0].size() << std::endl;
    std::cout << threeDMatrix[0][0].size() << std::endl;

    // 添加 batch 维度
    cv::Mat img_data;
    cv::Mat normImageBatched = image.reshape(1, 1);
    normImageBatched.convertTo(img_data, CV_32F);

    // 输出图像数据维度
    std::cout << "图像数据维度：" << img_data.size << std::endl;
    
    std::cout << static_cast<float>(image.at<cv::Vec3b>(0, 0)[0]) << std::endl;

    return 0;
}
